﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_NoiPhatHanh : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaNoiPhatHanh();

            layTenNoiPhatHanh();
        }
    }

    protected void layMaNoiPhatHanh()
    {
        string maNoiPhatHanhURL = Request.QueryString["MaNoiPhatHanh"];

        NoiPhatHanhBUS nphBUS = new NoiPhatHanhBUS();

        string maNoiPhatHanh = nphBUS.layMaNoiPhatHanh(maNoiPhatHanhURL);

        txtMaNoiPhatHanh.Text = maNoiPhatHanh;
    }

    protected void layTenNoiPhatHanh()
    {
        string maNoiPhatHanhURL = Request.QueryString["MaNoiPhatHanh"];

        NoiPhatHanhBUS nphBUS = new NoiPhatHanhBUS();

        string tenNoiPhatHanh = nphBUS.layTenNoiPhatHanh(maNoiPhatHanhURL);

        txtTenNoiPhatHanh.Text = tenNoiPhatHanh;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            NoiPhatHanh nphDTO = new NoiPhatHanh();
            nphDTO.MaNoiPhatHanh = txtMaNoiPhatHanh.Text.ToUpper();
            nphDTO.TenNoiPhatHanh = txtTenNoiPhatHanh.Text.ToUpper();

            //Kiem tra rong
            if (nphDTO.MaNoiPhatHanh.ToString() == string.Empty)
            {
                Alert.Show("Ma noi phat hanh khong duoc rong");
                return;
            }

            if (nphDTO.TenNoiPhatHanh.ToString() == string.Empty)
            {
                Alert.Show("Ten noi phat hanh khong duoc rong");
                return;
            }

            //Sua
            if (nphDTO.MaNoiPhatHanh.ToString() != string.Empty && nphDTO.TenNoiPhatHanh.ToString() != string.Empty)
            {
                NoiPhatHanhBUS nphBUS = new NoiPhatHanhBUS();

                string maNoiPhatHanhURL = Request.QueryString["MaNoiPhatHanh"];

                nphBUS.suaNoiPhatHanh(nphDTO, maNoiPhatHanhURL);

                Response.Redirect("ThamSoVanBan.aspx");
            }
        }
    }
    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoVanBan.aspx");
    }
}